var wellgroup={};
wellgroup.currentObj;
wellgroup.loadList=function (pageNo,isfirst){
	var queryStr=$("#wellgroup_queryText").val();
	$('#wellGroupTable').empty();
		var params = {pageSize:3,pageNo:(pageNo?pageNo:1),queryStr:queryStr};
		var config={columns:[{
			headerText:'井组名称',
			name:'wellGroupName'
		},{
			headerText:'录入人',
			name:'createName' 
 		},{
			headerText:'录入时间',
			name:'createDate' 
		},{
			headerText:'操作',
			name:'',
			renderer:function(str) {
				return '<input type="button" onclick="wellgroup.openDetailDialog('+this.wellGroupId+')" value="查看">'+
			    	'<input type="button" onclick="wellgroup.openUpdateDialog('+this.wellGroupId+')" value="修改">'+
			    	'<input type="button" onclick="wellgroup.doDelete('+this.wellGroupId+')" value="删除">';
			} 
		}
		],url:basePath+'app/wellGroup/loadList',params:params};
		$('#wellGroupTable').table(config,true,isfirst);
}
//新增操作
wellgroup.openAddDialog=function (){
	wellgroup.cleanAddDialog();
	$("#addWellGroupDialog").dialog({ modal: true });
}
wellgroup.cleanAddDialog=function (){
	$("#addWellGroup_Name").val("");
}
wellgroup.doAdd=function (){
	var wellGroupName=$("#addWellGroup_Name").val();
	$.post(basePath+"app/wellGroup/doAddWellGroup", {wellGroupName:wellGroupName}, function(data) {
		$("#addWellGroupDialog").dialog("destroy");
		wellgroup.loadList(1);//新增刷新为第一页
	});
}
//查看操作
wellgroup.openDetailDialog=function (wellGroupId){
	wellgroup.refreshDetailDialog(wellGroupId);
	$("#detailWellGroupDialog").dialog({ modal: false });
}
wellgroup.refreshDetailDialog=function (wellGroupId){
	var wg;
	for(var i in window.gridcache){
		if(wellGroupId==window.gridcache[i].wellGroupId){
			wg=window.gridcache[i];
			break;
		}
	}
	$("#detaillWellGroup_Name").text(wg.wellGroupName);
	$("#detaillWellGroup_OprName").text(wg.createName);
	$("#detaillWellGroup_OprDate").text(wg.createDate);
}
//修改操作
wellgroup.openUpdateDialog=function (wellGroupId){
	wellgroup.refreshUpdateDialog(wellGroupId);
	$("#updateWellGroupDialog").dialog({ modal: true });
}
wellgroup.refreshUpdateDialog=function (wellGroupId){
	var wg;
	for(var i in window.gridcache){
		if(wellGroupId==window.gridcache[i].wellGroupId){
			wg=window.gridcache[i];
			break;
		}
	}
	wellgroup.currentObj=wg;
	$("#updateWellGroup_Name").val(wg.wellGroupName);
}
wellgroup.doUpdate=function (){
	var wellGroupName=$("#updateWellGroup_Name").val();
	$.post(basePath+"app/wellGroup/doUpdateWellGroup", {wellGroupId:wellgroup.currentObj.wellGroupId,wellGroupName:wellGroupName}, function(data) {
		$("#updateWellGroupDialog").dialog("destroy");
		wellgroup.loadList();//修改刷新为当前页
	});
}
//删除操作
wellgroup.doDelete=function (wellGroupId){
	var i=window.confirm("确认删除？");
	if(i==true){
		$.post(basePath+"app/wellGroup/doDeleteWellGroup", {wellGroupId:wellGroupId}, function(data) {
			wellgroup.loadList();//修改刷新为当前页
		});
	}
}
$(function() {
	currentModule=wellgroup;//当前模块
    wellgroup.loadList(1,true);
    $("#wellGroupQuery").bind("keyup",function (event){
    	 if (event.keyCode=="13"){
    	 	wellgroup.loadList(1);
   		 }
    });
});